{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c6c8932b",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn.tree import DecisionTreeClassifier as DTC \n",
    "from sklearn.datasets import make_blobs  #创建团状数据\n",
    "from sklearn.model_selection import cross_val_score  #导入交叉验证的函数\n",
    "from sklearn.tree import DecisionTreeRegressor       #导入的回归树\n",
    "from sklearn.tree import DecisionTreeClassifier      # 直接导入分类树\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.model_selection import GridSearchCV     #网格搜索\n",
    "%matplotlib inline\n",
    "\n",
    "from sklearn import tree\n",
    "from sklearn.model_selection import train_test_split #训练集和测试集的切分函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "770eb7f4",
   "metadata": {},
   "outputs": [],
   "source": [
    "#导入.csv文件，用read_csv(),并读取前100行以及各列\n",
    "df = pd.read_csv('DATASET-B-1.csv',encoding='gbk')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "260de40c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>rowid</th>\n",
       "      <th>colid</th>\n",
       "      <th>time_id</th>\n",
       "      <th>aveSpeed</th>\n",
       "      <th>gridAcc</th>\n",
       "      <th>volume</th>\n",
       "      <th>speed_std</th>\n",
       "      <th>stopNum</th>\n",
       "      <th>date</th>\n",
       "      <th>labels</th>\n",
       "      <th>tmp_volume</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>12.357661</td>\n",
       "      <td>1.757799</td>\n",
       "      <td>1</td>\n",
       "      <td>16.997613</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>20161101</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>52</td>\n",
       "      <td>4.923624</td>\n",
       "      <td>-0.088537</td>\n",
       "      <td>1</td>\n",
       "      <td>3.682185</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>20161101</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>53</td>\n",
       "      <td>4.509885</td>\n",
       "      <td>-0.150552</td>\n",
       "      <td>2</td>\n",
       "      <td>2.469196</td>\n",
       "      <td>0.419045</td>\n",
       "      <td>20161101</td>\n",
       "      <td>0</td>\n",
       "      <td>-3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>55</td>\n",
       "      <td>4.745162</td>\n",
       "      <td>-0.306409</td>\n",
       "      <td>2</td>\n",
       "      <td>4.706964</td>\n",
       "      <td>6.800000</td>\n",
       "      <td>20161101</td>\n",
       "      <td>1</td>\n",
       "      <td>-2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>70</td>\n",
       "      <td>9.521660</td>\n",
       "      <td>1.466778</td>\n",
       "      <td>2</td>\n",
       "      <td>5.600533</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>20161101</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1048570</th>\n",
       "      <td>21</td>\n",
       "      <td>34</td>\n",
       "      <td>58</td>\n",
       "      <td>4.738167</td>\n",
       "      <td>-0.103800</td>\n",
       "      <td>32</td>\n",
       "      <td>6.423322</td>\n",
       "      <td>4.035129</td>\n",
       "      <td>20161108</td>\n",
       "      <td>1</td>\n",
       "      <td>-5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1048571</th>\n",
       "      <td>21</td>\n",
       "      <td>34</td>\n",
       "      <td>59</td>\n",
       "      <td>4.103481</td>\n",
       "      <td>0.020041</td>\n",
       "      <td>36</td>\n",
       "      <td>2.907494</td>\n",
       "      <td>6.800000</td>\n",
       "      <td>20161108</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1048572</th>\n",
       "      <td>21</td>\n",
       "      <td>34</td>\n",
       "      <td>60</td>\n",
       "      <td>6.764926</td>\n",
       "      <td>0.048575</td>\n",
       "      <td>36</td>\n",
       "      <td>8.945243</td>\n",
       "      <td>6.800000</td>\n",
       "      <td>20161108</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1048573</th>\n",
       "      <td>21</td>\n",
       "      <td>34</td>\n",
       "      <td>61</td>\n",
       "      <td>3.802730</td>\n",
       "      <td>-0.015998</td>\n",
       "      <td>25</td>\n",
       "      <td>3.284582</td>\n",
       "      <td>4.365995</td>\n",
       "      <td>20161108</td>\n",
       "      <td>1</td>\n",
       "      <td>-1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1048574</th>\n",
       "      <td>21</td>\n",
       "      <td>34</td>\n",
       "      <td>62</td>\n",
       "      <td>4.288511</td>\n",
       "      <td>-0.048667</td>\n",
       "      <td>39</td>\n",
       "      <td>3.574276</td>\n",
       "      <td>4.086778</td>\n",
       "      <td>20161108</td>\n",
       "      <td>1</td>\n",
       "      <td>-5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1048575 rows × 11 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         rowid  colid  time_id   aveSpeed   gridAcc  volume  speed_std  \\\n",
       "0            0      0        3  12.357661  1.757799       1  16.997613   \n",
       "1            0      0       52   4.923624 -0.088537       1   3.682185   \n",
       "2            0      0       53   4.509885 -0.150552       2   2.469196   \n",
       "3            0      0       55   4.745162 -0.306409       2   4.706964   \n",
       "4            0      0       70   9.521660  1.466778       2   5.600533   \n",
       "...        ...    ...      ...        ...       ...     ...        ...   \n",
       "1048570     21     34       58   4.738167 -0.103800      32   6.423322   \n",
       "1048571     21     34       59   4.103481  0.020041      36   2.907494   \n",
       "1048572     21     34       60   6.764926  0.048575      36   8.945243   \n",
       "1048573     21     34       61   3.802730 -0.015998      25   3.284582   \n",
       "1048574     21     34       62   4.288511 -0.048667      39   3.574276   \n",
       "\n",
       "          stopNum      date  labels  tmp_volume  \n",
       "0        0.000000  20161101       2           4  \n",
       "1        0.000000  20161101       0           3  \n",
       "2        0.419045  20161101       0          -3  \n",
       "3        6.800000  20161101       1          -2  \n",
       "4        0.000000  20161101       0           4  \n",
       "...           ...       ...     ...         ...  \n",
       "1048570  4.035129  20161108       1          -5  \n",
       "1048571  6.800000  20161108       1           2  \n",
       "1048572  6.800000  20161108       1           3  \n",
       "1048573  4.365995  20161108       1          -1  \n",
       "1048574  4.086778  20161108       1          -5  \n",
       "\n",
       "[1048575 rows x 11 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "390a10a0",
   "metadata": {},
   "outputs": [],
   "source": [
    "#导入.csv文件，用read_csv(),并读取前23行以及3,4,5,6,9三列\n",
    "df = pd.read_csv('DATASET-B-1.csv',encoding='gbk',nrows=23,usecols=[3,4,5,6,9])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "8231c66e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>aveSpeed</th>\n",
       "      <th>gridAcc</th>\n",
       "      <th>volume</th>\n",
       "      <th>speed_std</th>\n",
       "      <th>labels</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>12.357661</td>\n",
       "      <td>1.757799</td>\n",
       "      <td>1</td>\n",
       "      <td>16.997613</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>4.923624</td>\n",
       "      <td>-0.088537</td>\n",
       "      <td>1</td>\n",
       "      <td>3.682185</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4.509885</td>\n",
       "      <td>-0.150552</td>\n",
       "      <td>2</td>\n",
       "      <td>2.469196</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4.745162</td>\n",
       "      <td>-0.306409</td>\n",
       "      <td>2</td>\n",
       "      <td>4.706964</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>9.521660</td>\n",
       "      <td>1.466778</td>\n",
       "      <td>2</td>\n",
       "      <td>5.600533</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>7.045766</td>\n",
       "      <td>0.419753</td>\n",
       "      <td>1</td>\n",
       "      <td>5.830170</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7.875197</td>\n",
       "      <td>0.730289</td>\n",
       "      <td>1</td>\n",
       "      <td>3.243421</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8.543323</td>\n",
       "      <td>0.946036</td>\n",
       "      <td>1</td>\n",
       "      <td>3.215144</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>5.032903</td>\n",
       "      <td>0.033762</td>\n",
       "      <td>1</td>\n",
       "      <td>0.936438</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>9.372383</td>\n",
       "      <td>2.177034</td>\n",
       "      <td>3</td>\n",
       "      <td>9.939870</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>4.515025</td>\n",
       "      <td>0.215140</td>\n",
       "      <td>1</td>\n",
       "      <td>0.356847</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>5.042588</td>\n",
       "      <td>0.410076</td>\n",
       "      <td>1</td>\n",
       "      <td>3.922113</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>4.140771</td>\n",
       "      <td>-0.312588</td>\n",
       "      <td>2</td>\n",
       "      <td>4.164405</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>8.835525</td>\n",
       "      <td>-1.269601</td>\n",
       "      <td>1</td>\n",
       "      <td>13.601309</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>18.177828</td>\n",
       "      <td>2.299247</td>\n",
       "      <td>3</td>\n",
       "      <td>25.315800</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>5.369102</td>\n",
       "      <td>-0.739671</td>\n",
       "      <td>3</td>\n",
       "      <td>8.156808</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>4.912319</td>\n",
       "      <td>0.073399</td>\n",
       "      <td>1</td>\n",
       "      <td>0.565389</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>3.971022</td>\n",
       "      <td>0.087238</td>\n",
       "      <td>1</td>\n",
       "      <td>1.047519</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>6.162132</td>\n",
       "      <td>0.408302</td>\n",
       "      <td>2</td>\n",
       "      <td>3.718113</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>9.400328</td>\n",
       "      <td>0.202462</td>\n",
       "      <td>2</td>\n",
       "      <td>1.013628</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>14.903386</td>\n",
       "      <td>0.266442</td>\n",
       "      <td>2</td>\n",
       "      <td>6.633357</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>9.220533</td>\n",
       "      <td>0.110743</td>\n",
       "      <td>3</td>\n",
       "      <td>4.430716</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>14.213567</td>\n",
       "      <td>2.320732</td>\n",
       "      <td>1</td>\n",
       "      <td>7.377839</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     aveSpeed   gridAcc  volume  speed_std  labels\n",
       "0   12.357661  1.757799       1  16.997613       2\n",
       "1    4.923624 -0.088537       1   3.682185       0\n",
       "2    4.509885 -0.150552       2   2.469196       0\n",
       "3    4.745162 -0.306409       2   4.706964       1\n",
       "4    9.521660  1.466778       2   5.600533       0\n",
       "5    7.045766  0.419753       1   5.830170       0\n",
       "6    7.875197  0.730289       1   3.243421       0\n",
       "7    8.543323  0.946036       1   3.215144       0\n",
       "8    5.032903  0.033762       1   0.936438       0\n",
       "9    9.372383  2.177034       3   9.939870       0\n",
       "10   4.515025  0.215140       1   0.356847       0\n",
       "11   5.042588  0.410076       1   3.922113       0\n",
       "12   4.140771 -0.312588       2   4.164405       0\n",
       "13   8.835525 -1.269601       1  13.601309       0\n",
       "14  18.177828  2.299247       3  25.315800       2\n",
       "15   5.369102 -0.739671       3   8.156808       0\n",
       "16   4.912319  0.073399       1   0.565389       0\n",
       "17   3.971022  0.087238       1   1.047519       0\n",
       "18   6.162132  0.408302       2   3.718113       0\n",
       "19   9.400328  0.202462       2   1.013628       0\n",
       "20  14.903386  0.266442       2   6.633357       2\n",
       "21   9.220533  0.110743       3   4.430716       0\n",
       "22  14.213567  2.320732       1   7.377839       2"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "81adfe50",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 23 entries, 0 to 22\n",
      "Data columns (total 5 columns):\n",
      " #   Column     Non-Null Count  Dtype  \n",
      "---  ------     --------------  -----  \n",
      " 0   aveSpeed   23 non-null     float64\n",
      " 1   gridAcc    23 non-null     float64\n",
      " 2   volume     23 non-null     int64  \n",
      " 3   speed_std  23 non-null     float64\n",
      " 4   labels     23 non-null     int64  \n",
      "dtypes: float64(3), int64(2)\n",
      "memory usage: 1.0 KB\n"
     ]
    }
   ],
   "source": [
    "#了解数据概况，23行，6列\n",
    "df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ef1cd07f",
   "metadata": {},
   "outputs": [],
   "source": [
    "#提取标签和特征矩阵\n",
    "X = df.iloc[:,df.columns != \"labels\"]\n",
    "Y = df.iloc[:,df.columns == \"labels\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "0639c5a1",
   "metadata": {},
   "outputs": [],
   "source": [
    "#将数据集分为测试集和训练集，3/7分类\n",
    "Xtrain, Xtest, Ytrain, Ytest = train_test_split(X,Y,test_size=0.3\n",
    "                                                ,random_state=420)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "0ec42a73",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>aveSpeed</th>\n",
       "      <th>gridAcc</th>\n",
       "      <th>volume</th>\n",
       "      <th>speed_std</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>8.835525</td>\n",
       "      <td>-1.269601</td>\n",
       "      <td>1</td>\n",
       "      <td>13.601309</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>7.045766</td>\n",
       "      <td>0.419753</td>\n",
       "      <td>1</td>\n",
       "      <td>5.830170</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>4.140771</td>\n",
       "      <td>-0.312588</td>\n",
       "      <td>2</td>\n",
       "      <td>4.164405</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>4.912319</td>\n",
       "      <td>0.073399</td>\n",
       "      <td>1</td>\n",
       "      <td>0.565389</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4.745162</td>\n",
       "      <td>-0.306409</td>\n",
       "      <td>2</td>\n",
       "      <td>4.706964</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>9.521660</td>\n",
       "      <td>1.466778</td>\n",
       "      <td>2</td>\n",
       "      <td>5.600533</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>14.903386</td>\n",
       "      <td>0.266442</td>\n",
       "      <td>2</td>\n",
       "      <td>6.633357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8.543323</td>\n",
       "      <td>0.946036</td>\n",
       "      <td>1</td>\n",
       "      <td>3.215144</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>6.162132</td>\n",
       "      <td>0.408302</td>\n",
       "      <td>2</td>\n",
       "      <td>3.718113</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>9.220533</td>\n",
       "      <td>0.110743</td>\n",
       "      <td>3</td>\n",
       "      <td>4.430716</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>4.515025</td>\n",
       "      <td>0.215140</td>\n",
       "      <td>1</td>\n",
       "      <td>0.356847</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>18.177828</td>\n",
       "      <td>2.299247</td>\n",
       "      <td>3</td>\n",
       "      <td>25.315800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>9.400328</td>\n",
       "      <td>0.202462</td>\n",
       "      <td>2</td>\n",
       "      <td>1.013628</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7.875197</td>\n",
       "      <td>0.730289</td>\n",
       "      <td>1</td>\n",
       "      <td>3.243421</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>5.032903</td>\n",
       "      <td>0.033762</td>\n",
       "      <td>1</td>\n",
       "      <td>0.936438</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>3.971022</td>\n",
       "      <td>0.087238</td>\n",
       "      <td>1</td>\n",
       "      <td>1.047519</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     aveSpeed   gridAcc  volume  speed_std\n",
       "13   8.835525 -1.269601       1  13.601309\n",
       "5    7.045766  0.419753       1   5.830170\n",
       "12   4.140771 -0.312588       2   4.164405\n",
       "16   4.912319  0.073399       1   0.565389\n",
       "3    4.745162 -0.306409       2   4.706964\n",
       "4    9.521660  1.466778       2   5.600533\n",
       "20  14.903386  0.266442       2   6.633357\n",
       "7    8.543323  0.946036       1   3.215144\n",
       "18   6.162132  0.408302       2   3.718113\n",
       "21   9.220533  0.110743       3   4.430716\n",
       "10   4.515025  0.215140       1   0.356847\n",
       "14  18.177828  2.299247       3  25.315800\n",
       "19   9.400328  0.202462       2   1.013628\n",
       "6    7.875197  0.730289       1   3.243421\n",
       "8    5.032903  0.033762       1   0.936438\n",
       "17   3.971022  0.087238       1   1.047519"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Xtrain"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "d2f52109",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 16 entries, 13 to 17\n",
      "Data columns (total 4 columns):\n",
      " #   Column     Non-Null Count  Dtype  \n",
      "---  ------     --------------  -----  \n",
      " 0   aveSpeed   16 non-null     float64\n",
      " 1   gridAcc    16 non-null     float64\n",
      " 2   volume     16 non-null     int64  \n",
      " 3   speed_std  16 non-null     float64\n",
      "dtypes: float64(3), int64(1)\n",
      "memory usage: 640.0 bytes\n"
     ]
    }
   ],
   "source": [
    "#了解数据概况，16行，4列\n",
    "Xtrain.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "39db2705",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>labels</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    labels\n",
       "13       0\n",
       "5        0\n",
       "12       0\n",
       "16       0\n",
       "3        1\n",
       "4        0\n",
       "20       2\n",
       "7        0\n",
       "18       0\n",
       "21       0\n",
       "10       0\n",
       "14       2\n",
       "19       0\n",
       "6        0\n",
       "8        0\n",
       "17       0"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Ytrain"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "98234b96",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>aveSpeed</th>\n",
       "      <th>gridAcc</th>\n",
       "      <th>volume</th>\n",
       "      <th>speed_std</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4.509885</td>\n",
       "      <td>-0.150552</td>\n",
       "      <td>2</td>\n",
       "      <td>2.469196</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>4.923624</td>\n",
       "      <td>-0.088537</td>\n",
       "      <td>1</td>\n",
       "      <td>3.682185</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>5.042588</td>\n",
       "      <td>0.410076</td>\n",
       "      <td>1</td>\n",
       "      <td>3.922113</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>5.369102</td>\n",
       "      <td>-0.739671</td>\n",
       "      <td>3</td>\n",
       "      <td>8.156808</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>9.372383</td>\n",
       "      <td>2.177034</td>\n",
       "      <td>3</td>\n",
       "      <td>9.939870</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>14.213567</td>\n",
       "      <td>2.320732</td>\n",
       "      <td>1</td>\n",
       "      <td>7.377839</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>12.357661</td>\n",
       "      <td>1.757799</td>\n",
       "      <td>1</td>\n",
       "      <td>16.997613</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     aveSpeed   gridAcc  volume  speed_std\n",
       "2    4.509885 -0.150552       2   2.469196\n",
       "1    4.923624 -0.088537       1   3.682185\n",
       "11   5.042588  0.410076       1   3.922113\n",
       "15   5.369102 -0.739671       3   8.156808\n",
       "9    9.372383  2.177034       3   9.939870\n",
       "22  14.213567  2.320732       1   7.377839\n",
       "0   12.357661  1.757799       1  16.997613"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Xtest"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "9486cc9d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>labels</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    labels\n",
       "2        0\n",
       "1        0\n",
       "11       0\n",
       "15       0\n",
       "9        0\n",
       "22       2\n",
       "0        2"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Ytest"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "2d25a7a1",
   "metadata": {},
   "outputs": [],
   "source": [
    "#修正测试集和训练集的索引\n",
    "for i in [Xtrain, Xtest, Ytrain, Ytest]:\n",
    "    i.index = range(i.shape[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "b08f587e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>aveSpeed</th>\n",
       "      <th>gridAcc</th>\n",
       "      <th>volume</th>\n",
       "      <th>speed_std</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>8.835525</td>\n",
       "      <td>-1.269601</td>\n",
       "      <td>1</td>\n",
       "      <td>13.601309</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>7.045766</td>\n",
       "      <td>0.419753</td>\n",
       "      <td>1</td>\n",
       "      <td>5.830170</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4.140771</td>\n",
       "      <td>-0.312588</td>\n",
       "      <td>2</td>\n",
       "      <td>4.164405</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4.912319</td>\n",
       "      <td>0.073399</td>\n",
       "      <td>1</td>\n",
       "      <td>0.565389</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4.745162</td>\n",
       "      <td>-0.306409</td>\n",
       "      <td>2</td>\n",
       "      <td>4.706964</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>9.521660</td>\n",
       "      <td>1.466778</td>\n",
       "      <td>2</td>\n",
       "      <td>5.600533</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>14.903386</td>\n",
       "      <td>0.266442</td>\n",
       "      <td>2</td>\n",
       "      <td>6.633357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8.543323</td>\n",
       "      <td>0.946036</td>\n",
       "      <td>1</td>\n",
       "      <td>3.215144</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>6.162132</td>\n",
       "      <td>0.408302</td>\n",
       "      <td>2</td>\n",
       "      <td>3.718113</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>9.220533</td>\n",
       "      <td>0.110743</td>\n",
       "      <td>3</td>\n",
       "      <td>4.430716</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>4.515025</td>\n",
       "      <td>0.215140</td>\n",
       "      <td>1</td>\n",
       "      <td>0.356847</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>18.177828</td>\n",
       "      <td>2.299247</td>\n",
       "      <td>3</td>\n",
       "      <td>25.315800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>9.400328</td>\n",
       "      <td>0.202462</td>\n",
       "      <td>2</td>\n",
       "      <td>1.013628</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>7.875197</td>\n",
       "      <td>0.730289</td>\n",
       "      <td>1</td>\n",
       "      <td>3.243421</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>5.032903</td>\n",
       "      <td>0.033762</td>\n",
       "      <td>1</td>\n",
       "      <td>0.936438</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>3.971022</td>\n",
       "      <td>0.087238</td>\n",
       "      <td>1</td>\n",
       "      <td>1.047519</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     aveSpeed   gridAcc  volume  speed_std\n",
       "0    8.835525 -1.269601       1  13.601309\n",
       "1    7.045766  0.419753       1   5.830170\n",
       "2    4.140771 -0.312588       2   4.164405\n",
       "3    4.912319  0.073399       1   0.565389\n",
       "4    4.745162 -0.306409       2   4.706964\n",
       "5    9.521660  1.466778       2   5.600533\n",
       "6   14.903386  0.266442       2   6.633357\n",
       "7    8.543323  0.946036       1   3.215144\n",
       "8    6.162132  0.408302       2   3.718113\n",
       "9    9.220533  0.110743       3   4.430716\n",
       "10   4.515025  0.215140       1   0.356847\n",
       "11  18.177828  2.299247       3  25.315800\n",
       "12   9.400328  0.202462       2   1.013628\n",
       "13   7.875197  0.730289       1   3.243421\n",
       "14   5.032903  0.033762       1   0.936438\n",
       "15   3.971022  0.087238       1   1.047519"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Xtrain.head(23)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "74127cfc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>labels</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    labels\n",
       "0        0\n",
       "1        0\n",
       "2        0\n",
       "3        0\n",
       "4        1\n",
       "5        0\n",
       "6        2\n",
       "7        0\n",
       "8        0\n",
       "9        0\n",
       "10       0\n",
       "11       2\n",
       "12       0\n",
       "13       0\n",
       "14       0\n",
       "15       0"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Ytrain"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "29a9dbb0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>aveSpeed</th>\n",
       "      <th>gridAcc</th>\n",
       "      <th>volume</th>\n",
       "      <th>speed_std</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>4.509885</td>\n",
       "      <td>-0.150552</td>\n",
       "      <td>2</td>\n",
       "      <td>2.469196</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>4.923624</td>\n",
       "      <td>-0.088537</td>\n",
       "      <td>1</td>\n",
       "      <td>3.682185</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>5.042588</td>\n",
       "      <td>0.410076</td>\n",
       "      <td>1</td>\n",
       "      <td>3.922113</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5.369102</td>\n",
       "      <td>-0.739671</td>\n",
       "      <td>3</td>\n",
       "      <td>8.156808</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>9.372383</td>\n",
       "      <td>2.177034</td>\n",
       "      <td>3</td>\n",
       "      <td>9.939870</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>14.213567</td>\n",
       "      <td>2.320732</td>\n",
       "      <td>1</td>\n",
       "      <td>7.377839</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>12.357661</td>\n",
       "      <td>1.757799</td>\n",
       "      <td>1</td>\n",
       "      <td>16.997613</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    aveSpeed   gridAcc  volume  speed_std\n",
       "0   4.509885 -0.150552       2   2.469196\n",
       "1   4.923624 -0.088537       1   3.682185\n",
       "2   5.042588  0.410076       1   3.922113\n",
       "3   5.369102 -0.739671       3   8.156808\n",
       "4   9.372383  2.177034       3   9.939870\n",
       "5  14.213567  2.320732       1   7.377839\n",
       "6  12.357661  1.757799       1  16.997613"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Xtest.head(23)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "1e37bc2a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>labels</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   labels\n",
       "0       0\n",
       "1       0\n",
       "2       0\n",
       "3       0\n",
       "4       0\n",
       "5       2\n",
       "6       2"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Ytest"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "797767f2",
   "metadata": {},
   "source": [
    "寻找最优建树参数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "c395daaa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.8571428571428571"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#实例化模型、用随机数种子默认参数，训练模型并查看准确率\n",
    "clf = DecisionTreeClassifier(random_state=25)\n",
    "clf = clf.fit(Xtrain, Ytrain)\n",
    "score_ = clf.score(Xtest, Ytest)\n",
    "score_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "445d0586",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\ANACONDA\\lib\\site-packages\\sklearn\\model_selection\\_split.py:676: UserWarning: The least populated class in y has only 1 members, which is less than n_splits=10.\n",
      "  warnings.warn(\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "0.9"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "score = cross_val_score(clf,Xtrain,Ytrain,cv=10).mean() #十折交叉验证，查看准确率均值\n",
    "score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "7980438e",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\ANACONDA\\lib\\site-packages\\sklearn\\model_selection\\_split.py:676: UserWarning: The least populated class in y has only 1 members, which is less than n_splits=10.\n",
      "  warnings.warn(\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "0.04000000000000001"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#查看方差\n",
    "var = cross_val_score(clf,Xtrain,Ytrain,cv=10).var()\n",
    "var"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "5f04c2b8",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\ANACONDA\\lib\\site-packages\\sklearn\\model_selection\\_split.py:676: UserWarning: The least populated class in y has only 1 members, which is less than n_splits=10.\n",
      "  warnings.warn(\n",
      "D:\\ANACONDA\\lib\\site-packages\\sklearn\\model_selection\\_split.py:676: UserWarning: The least populated class in y has only 1 members, which is less than n_splits=10.\n",
      "  warnings.warn(\n",
      "D:\\ANACONDA\\lib\\site-packages\\sklearn\\model_selection\\_split.py:676: UserWarning: The least populated class in y has only 1 members, which is less than n_splits=10.\n",
      "  warnings.warn(\n",
      "D:\\ANACONDA\\lib\\site-packages\\sklearn\\model_selection\\_split.py:676: UserWarning: The least populated class in y has only 1 members, which is less than n_splits=10.\n",
      "  warnings.warn(\n",
      "D:\\ANACONDA\\lib\\site-packages\\sklearn\\model_selection\\_split.py:676: UserWarning: The least populated class in y has only 1 members, which is less than n_splits=10.\n",
      "  warnings.warn(\n",
      "D:\\ANACONDA\\lib\\site-packages\\sklearn\\model_selection\\_split.py:676: UserWarning: The least populated class in y has only 1 members, which is less than n_splits=10.\n",
      "  warnings.warn(\n",
      "D:\\ANACONDA\\lib\\site-packages\\sklearn\\model_selection\\_split.py:676: UserWarning: The least populated class in y has only 1 members, which is less than n_splits=10.\n",
      "  warnings.warn(\n",
      "D:\\ANACONDA\\lib\\site-packages\\sklearn\\model_selection\\_split.py:676: UserWarning: The least populated class in y has only 1 members, which is less than n_splits=10.\n",
      "  warnings.warn(\n",
      "D:\\ANACONDA\\lib\\site-packages\\sklearn\\model_selection\\_split.py:676: UserWarning: The least populated class in y has only 1 members, which is less than n_splits=10.\n",
      "  warnings.warn(\n",
      "D:\\ANACONDA\\lib\\site-packages\\sklearn\\model_selection\\_split.py:676: UserWarning: The least populated class in y has only 1 members, which is less than n_splits=10.\n",
      "  warnings.warn(\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.95\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAiwAAAGdCAYAAAAxCSikAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/NK7nSAAAACXBIWXMAAA9hAAAPYQGoP6dpAAA6NUlEQVR4nO3df1xUdaL/8fc4DDAaIIqiJgKpGYb9EFoENHMzDIt097Zpu7m63e1+uw+7K3rrlptuZaVbrm3dTEuNNrc2vY8tK8tS2vInJoI/8ldi+QNTiHQTVBRwON8/pmEl5Mfw6xyY1/PxmAeH45mZ98nd5t35fOZzbIZhGAIAALCwDmYHAAAAqA+FBQAAWB6FBQAAWB6FBQAAWB6FBQAAWB6FBQAAWB6FBQAAWB6FBQAAWJ6f2QGaS2VlpY4fP66goCDZbDaz4wAAgAYwDEOnT59Wr1691KFD7ddR2k1hOX78uCIiIsyOAQAAGuHo0aPq3bt3rX/ebgpLUFCQJPcJBwcHm5wGAAA0RElJiSIiIqo+x2vTbgqLZxgoODiYwgIAQBtT33QOJt0CAADLo7AAAADLo7AAAADLazdzWBrC5XKpoqLC7Bhtkt1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iYm887kyZP1t7/9Te+9956CgoKqxiBDQkLkdDpNTtdwv//975WamqqIiAidPn1ay5Yt09q1a/Xxxx+bHc0rQUFBNeYPderUSV27dm1T84oefPBBpaWlqU+fPioqKtJTTz2lkpKSNvdfwFOnTlVSUpJmz56tu+66S9nZ2Vq0aJEWLVpkdrRGqays1GuvvaaJEyfKz69t/us9LS1NTz/9tPr06aOrr75a27dv13PPPad7773X7GheW716tQzD0IABA/TVV1/poYce0oABA/Sb3/zG7Gi1qu+zLz09XbNnz1b//v3Vv39/zZ49Wx07dtQvf/nLlg/X4t9DaqM+++wzQ1KNx8SJE82O5pVLnYMk47XXXjM7mlfuvfdeIzIy0vD39ze6detm3HzzzcaaNWvMjtUs2uLXmseNG2f07NnTcDgcRq9evYyf//znxp49e8yO1SgrV640YmNjjYCAAOOqq64yFi1aZHakRlu9erUhydi/f7/ZURqtpKTEmDJlitGnTx8jMDDQuOKKK4xHH33UKCsrMzua15YvX25cccUVhr+/v9GjRw9j8uTJxqlTp8yOVaf6PvsqKyuNxx57zOjRo4cREBBg3HjjjcauXbtaJZvNMAyj5WsRAABA4zGHBQAAWB6FBQAAWB6FBQAAWB6FBQAAWB6FBQAAWB6FBQAAWB6FBQAAWB6FBQAAWB6FBQAAWB6FBQAAWB6FBQAAWB6FBQAAWN7/B8Mbx5QM0ylUAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#对最大树深做学习曲线，看拟合效果，结果显示2左右可以达到94%左右的准确率  \n",
    "tr = []\n",
    "te = []\n",
    "for i in range(10):\n",
    "    clf = DecisionTreeClassifier(random_state=25\n",
    "                                 ,max_depth=i+1\n",
    "                                )\n",
    "    clf = clf.fit(Xtrain, Ytrain)\n",
    "    score_tr = clf.score(Xtrain,Ytrain)\n",
    "    score_te = cross_val_score(clf,Xtrain,Ytrain,cv=10).mean()\n",
    "    tr.append(score_tr)\n",
    "    te.append(score_te)\n",
    "print(max(te))\n",
    "plt.plot(range(1,11),tr,color=\"red\",label=\"train\")\n",
    "plt.plot(range(1,11),te,color=\"blue\",label=\"test\")\n",
    "plt.xticks(range(1,11))\n",
    "plt.legend()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "7a8ee4c2",
   "metadata": {},
   "outputs": [],
   "source": [
    "#查看所有参数结果，寻求最优设置参数\n",
    "import numpy as np\n",
    "gini_thresholds = np.linspace(0,0.5,20)\n",
    "\n",
    "parameters = {'splitter':('best','random')\n",
    "              ,'criterion':(\"gini\",\"entropy\")\n",
    "              ,\"max_depth\":[*range(1,10)]\n",
    "              ,'min_samples_leaf':[*range(1,50,5)]\n",
    "              ,'min_impurity_decrease':[*np.linspace(0,0.5,20)]\n",
    "             }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "9e12f22b",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\ANACONDA\\lib\\site-packages\\sklearn\\model_selection\\_split.py:676: UserWarning: The least populated class in y has only 1 members, which is less than n_splits=10.\n",
      "  warnings.warn(\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "GridSearchCV(cv=10, estimator=DecisionTreeClassifier(random_state=25),\n",
       "             param_grid={'criterion': ('gini', 'entropy'),\n",
       "                         'max_depth': [1, 2, 3, 4, 5, 6, 7, 8, 9],\n",
       "                         'min_impurity_decrease': [0.0, 0.02631578947368421,\n",
       "                                                   0.05263157894736842,\n",
       "                                                   0.07894736842105263,\n",
       "                                                   0.10526315789473684,\n",
       "                                                   0.13157894736842105,\n",
       "                                                   0.15789473684210525,\n",
       "                                                   0.18421052631578946,\n",
       "                                                   0.21052631578947367,\n",
       "                                                   0.23684210526315788,\n",
       "                                                   0.2631578947368421,\n",
       "                                                   0.2894736842105263,\n",
       "                                                   0.3157894736842105,\n",
       "                                                   0.3421052631578947,\n",
       "                                                   0.3684210526315789,\n",
       "                                                   0.39473684210526316,\n",
       "                                                   0.42105263157894735,\n",
       "                                                   0.4473684210526315,\n",
       "                                                   0.47368421052631576, 0.5],\n",
       "                         'min_samples_leaf': [1, 6, 11, 16, 21, 26, 31, 36, 41,\n",
       "                                              46],\n",
       "                         'splitter': ('best', 'random')})"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#网格搜索，得到最优参数\n",
    "clf = DecisionTreeClassifier(random_state=25)\n",
    "GS = GridSearchCV(clf, parameters, cv=10)\n",
    "GS.fit(Xtrain,Ytrain)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "705f2b91",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'criterion': 'gini',\n",
       " 'max_depth': 1,\n",
       " 'min_impurity_decrease': 0.0,\n",
       " 'min_samples_leaf': 1,\n",
       " 'splitter': 'best'}"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#属性best_params_查看调整出来的最佳参数\n",
    "GS.best_params_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "76028f7e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.95"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#属性best_score_查看最佳分数\n",
    "GS.best_score_"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4020051c",
   "metadata": {},
   "source": [
    "建树"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "c941d475",
   "metadata": {},
   "outputs": [],
   "source": [
    "#在CMD中执行命令：conda install python-graphviz\n",
    "import graphviz"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "79bbe23a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'0.20.1'"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#可视化包的版本\n",
    "graphviz.__version__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "3bca9eb2",
   "metadata": {},
   "outputs": [],
   "source": [
    "feature_name = ['aveSpeed','gridAcc','volume','speed_std','labels']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "bab7301c",
   "metadata": {},
   "outputs": [],
   "source": [
    "clf = clf.fit(Xtrain, Ytrain)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "467a39f8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Generated by graphviz version 2.50.0 (0)\n",
       " -->\n",
       "<!-- Title: Tree Pages: 1 -->\n",
       "<svg width=\"379pt\" height=\"373pt\"\n",
       " viewBox=\"0.00 0.00 379.00 373.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 369)\">\n",
       "<title>Tree</title>\n",
       "<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-369 375,-369 375,4 -4,4\"/>\n",
       "<!-- 0 -->\n",
       "<g id=\"node1\" class=\"node\">\n",
       "<title>0</title>\n",
       "<path fill=\"#eb9c63\" stroke=\"black\" d=\"M296.5,-365C296.5,-365 203.5,-365 203.5,-365 197.5,-365 191.5,-359 191.5,-353 191.5,-353 191.5,-309 191.5,-309 191.5,-303 197.5,-297 203.5,-297 203.5,-297 296.5,-297 296.5,-297 302.5,-297 308.5,-303 308.5,-309 308.5,-309 308.5,-353 308.5,-353 308.5,-359 302.5,-365 296.5,-365\"/>\n",
       "<text text-anchor=\"middle\" x=\"250\" y=\"-349.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">X[0] &lt;= 12.213</text>\n",
       "<text text-anchor=\"middle\" x=\"250\" y=\"-334.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">gini = 0.32</text>\n",
       "<text text-anchor=\"middle\" x=\"250\" y=\"-319.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 16</text>\n",
       "<text text-anchor=\"middle\" x=\"250\" y=\"-304.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [13, 1, 2]</text>\n",
       "</g>\n",
       "<!-- 1 -->\n",
       "<g id=\"node2\" class=\"node\">\n",
       "<title>1</title>\n",
       "<path fill=\"#e78b48\" stroke=\"black\" d=\"M230.5,-261C230.5,-261 137.5,-261 137.5,-261 131.5,-261 125.5,-255 125.5,-249 125.5,-249 125.5,-205 125.5,-205 125.5,-199 131.5,-193 137.5,-193 137.5,-193 230.5,-193 230.5,-193 236.5,-193 242.5,-199 242.5,-205 242.5,-205 242.5,-249 242.5,-249 242.5,-255 236.5,-261 230.5,-261\"/>\n",
       "<text text-anchor=\"middle\" x=\"184\" y=\"-245.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">X[1] &lt;= &#45;0.136</text>\n",
       "<text text-anchor=\"middle\" x=\"184\" y=\"-230.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">gini = 0.133</text>\n",
       "<text text-anchor=\"middle\" x=\"184\" y=\"-215.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 14</text>\n",
       "<text text-anchor=\"middle\" x=\"184\" y=\"-200.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [13, 1, 0]</text>\n",
       "</g>\n",
       "<!-- 0&#45;&gt;1 -->\n",
       "<g id=\"edge1\" class=\"edge\">\n",
       "<title>0&#45;&gt;1</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M228.57,-296.88C222.98,-288.24 216.88,-278.82 211.04,-269.79\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"213.92,-267.79 205.55,-261.3 208.04,-271.6 213.92,-267.79\"/>\n",
       "<text text-anchor=\"middle\" x=\"200.31\" y=\"-282.04\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">True</text>\n",
       "</g>\n",
       "<!-- 6 -->\n",
       "<g id=\"node7\" class=\"node\">\n",
       "<title>6</title>\n",
       "<path fill=\"#8139e5\" stroke=\"black\" d=\"M359,-253.5C359,-253.5 273,-253.5 273,-253.5 267,-253.5 261,-247.5 261,-241.5 261,-241.5 261,-212.5 261,-212.5 261,-206.5 267,-200.5 273,-200.5 273,-200.5 359,-200.5 359,-200.5 365,-200.5 371,-206.5 371,-212.5 371,-212.5 371,-241.5 371,-241.5 371,-247.5 365,-253.5 359,-253.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"316\" y=\"-238.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">gini = 0.0</text>\n",
       "<text text-anchor=\"middle\" x=\"316\" y=\"-223.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 2</text>\n",
       "<text text-anchor=\"middle\" x=\"316\" y=\"-208.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [0, 0, 2]</text>\n",
       "</g>\n",
       "<!-- 0&#45;&gt;6 -->\n",
       "<g id=\"edge6\" class=\"edge\">\n",
       "<title>0&#45;&gt;6</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M271.43,-296.88C278.62,-285.78 286.64,-273.37 293.88,-262.18\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"296.99,-263.82 299.49,-253.52 291.12,-260.01 296.99,-263.82\"/>\n",
       "<text text-anchor=\"middle\" x=\"304.73\" y=\"-274.26\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">False</text>\n",
       "</g>\n",
       "<!-- 2 -->\n",
       "<g id=\"node3\" class=\"node\">\n",
       "<title>2</title>\n",
       "<path fill=\"#f2c09c\" stroke=\"black\" d=\"M162,-157C162,-157 76,-157 76,-157 70,-157 64,-151 64,-145 64,-145 64,-101 64,-101 64,-95 70,-89 76,-89 76,-89 162,-89 162,-89 168,-89 174,-95 174,-101 174,-101 174,-145 174,-145 174,-151 168,-157 162,-157\"/>\n",
       "<text text-anchor=\"middle\" x=\"119\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">X[1] &lt;= &#45;0.309</text>\n",
       "<text text-anchor=\"middle\" x=\"119\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">gini = 0.444</text>\n",
       "<text text-anchor=\"middle\" x=\"119\" y=\"-111.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 3</text>\n",
       "<text text-anchor=\"middle\" x=\"119\" y=\"-96.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [2, 1, 0]</text>\n",
       "</g>\n",
       "<!-- 1&#45;&gt;2 -->\n",
       "<g id=\"edge2\" class=\"edge\">\n",
       "<title>1&#45;&gt;2</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M162.9,-192.88C157.39,-184.24 151.38,-174.82 145.63,-165.79\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"148.55,-163.85 140.22,-157.3 142.64,-167.61 148.55,-163.85\"/>\n",
       "</g>\n",
       "<!-- 5 -->\n",
       "<g id=\"node6\" class=\"node\">\n",
       "<title>5</title>\n",
       "<path fill=\"#e58139\" stroke=\"black\" d=\"M296,-149.5C296,-149.5 204,-149.5 204,-149.5 198,-149.5 192,-143.5 192,-137.5 192,-137.5 192,-108.5 192,-108.5 192,-102.5 198,-96.5 204,-96.5 204,-96.5 296,-96.5 296,-96.5 302,-96.5 308,-102.5 308,-108.5 308,-108.5 308,-137.5 308,-137.5 308,-143.5 302,-149.5 296,-149.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"250\" y=\"-134.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">gini = 0.0</text>\n",
       "<text text-anchor=\"middle\" x=\"250\" y=\"-119.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 11</text>\n",
       "<text text-anchor=\"middle\" x=\"250\" y=\"-104.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [11, 0, 0]</text>\n",
       "</g>\n",
       "<!-- 1&#45;&gt;5 -->\n",
       "<g id=\"edge5\" class=\"edge\">\n",
       "<title>1&#45;&gt;5</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M205.43,-192.88C212.62,-181.78 220.64,-169.37 227.88,-158.18\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"230.99,-159.82 233.49,-149.52 225.12,-156.01 230.99,-159.82\"/>\n",
       "</g>\n",
       "<!-- 3 -->\n",
       "<g id=\"node4\" class=\"node\">\n",
       "<title>3</title>\n",
       "<path fill=\"#e58139\" stroke=\"black\" d=\"M98,-53C98,-53 12,-53 12,-53 6,-53 0,-47 0,-41 0,-41 0,-12 0,-12 0,-6 6,0 12,0 12,0 98,0 98,0 104,0 110,-6 110,-12 110,-12 110,-41 110,-41 110,-47 104,-53 98,-53\"/>\n",
       "<text text-anchor=\"middle\" x=\"55\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">gini = 0.0</text>\n",
       "<text text-anchor=\"middle\" x=\"55\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 2</text>\n",
       "<text text-anchor=\"middle\" x=\"55\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [2, 0, 0]</text>\n",
       "</g>\n",
       "<!-- 2&#45;&gt;3 -->\n",
       "<g id=\"edge3\" class=\"edge\">\n",
       "<title>2&#45;&gt;3</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M96.62,-88.95C90.61,-80.07 84.1,-70.46 78.05,-61.54\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"80.94,-59.55 72.43,-53.24 75.14,-63.48 80.94,-59.55\"/>\n",
       "</g>\n",
       "<!-- 4 -->\n",
       "<g id=\"node5\" class=\"node\">\n",
       "<title>4</title>\n",
       "<path fill=\"#39e581\" stroke=\"black\" d=\"M226,-53C226,-53 140,-53 140,-53 134,-53 128,-47 128,-41 128,-41 128,-12 128,-12 128,-6 134,0 140,0 140,0 226,0 226,0 232,0 238,-6 238,-12 238,-12 238,-41 238,-41 238,-47 232,-53 226,-53\"/>\n",
       "<text text-anchor=\"middle\" x=\"183\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">gini = 0.0</text>\n",
       "<text text-anchor=\"middle\" x=\"183\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 1</text>\n",
       "<text text-anchor=\"middle\" x=\"183\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [0, 1, 0]</text>\n",
       "</g>\n",
       "<!-- 2&#45;&gt;4 -->\n",
       "<g id=\"edge4\" class=\"edge\">\n",
       "<title>2&#45;&gt;4</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M141.38,-88.95C147.39,-80.07 153.9,-70.46 159.95,-61.54\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"162.86,-63.48 165.57,-53.24 157.06,-59.55 162.86,-63.48\"/>\n",
       "</g>\n",
       "</g>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<graphviz.sources.Source at 0x1a419ca6ee0>"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dot_data = tree.export_graphviz(clf    #训练好的模型\n",
    "                                ,out_file = None\n",
    "                                ,filled=True\n",
    "                                ,rounded=True\n",
    "                               )\n",
    "graph = graphviz.Source(dot_data)\n",
    "graph"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "e84841d2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.63763066, 0.36236934, 0.        , 0.        ])"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#特征重要性\n",
    "clf.feature_importances_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "c5bda4f7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('aveSpeed', 0.6376306620209058),\n",
       " ('gridAcc', 0.36236933797909415),\n",
       " ('volume', 0.0),\n",
       " ('speed_std', 0.0)]"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[*zip(feature_name,clf.feature_importances_)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "4d172ede",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'决策树.pdf'"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#保存生成的图形\n",
    "graph.render(\"决策树\") #生成PDF文件，文件中无法显示中文"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "43e5ae40",
   "metadata": {},
   "source": [
    "决策树剪枝"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "3f0aa612",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DecisionTreeClassifier()"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "DTC()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "23a47e39",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#我们的树对训练集的拟合程度如何？\n",
    "score_train = clf.score(Xtrain, Ytrain)\n",
    "score_train"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "f474867d",
   "metadata": {},
   "outputs": [],
   "source": [
    "clf = tree.DecisionTreeClassifier(criterion=\"gini\"\n",
    "                                  ,random_state=30\n",
    "                                  ,splitter=\"random\"\n",
    "                                  ,max_depth=1\n",
    "                                 ) #实例化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "452076ad",
   "metadata": {},
   "outputs": [],
   "source": [
    "clf = clf.fit(Xtrain, Ytrain) #训练模型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "e8d3c854",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Generated by graphviz version 2.50.0 (0)\n",
       " -->\n",
       "<!-- Title: Tree Pages: 1 -->\n",
       "<svg width=\"254pt\" height=\"165pt\"\n",
       " viewBox=\"0.00 0.00 253.50 165.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 161)\">\n",
       "<title>Tree</title>\n",
       "<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-161 249.5,-161 249.5,4 -4,4\"/>\n",
       "<!-- 0 -->\n",
       "<g id=\"node1\" class=\"node\">\n",
       "<title>0</title>\n",
       "<path fill=\"#eb9c63\" stroke=\"black\" d=\"M171,-157C171,-157 78,-157 78,-157 72,-157 66,-151 66,-145 66,-145 66,-101 66,-101 66,-95 72,-89 78,-89 78,-89 171,-89 171,-89 177,-89 183,-95 183,-101 183,-101 183,-145 183,-145 183,-151 177,-157 171,-157\"/>\n",
       "<text text-anchor=\"middle\" x=\"124.5\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">X[1] &lt;= 1.941</text>\n",
       "<text text-anchor=\"middle\" x=\"124.5\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">gini = 0.32</text>\n",
       "<text text-anchor=\"middle\" x=\"124.5\" y=\"-111.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 16</text>\n",
       "<text text-anchor=\"middle\" x=\"124.5\" y=\"-96.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [13, 1, 2]</text>\n",
       "</g>\n",
       "<!-- 1 -->\n",
       "<g id=\"node2\" class=\"node\">\n",
       "<title>1</title>\n",
       "<path fill=\"#e99355\" stroke=\"black\" d=\"M105,-53C105,-53 12,-53 12,-53 6,-53 0,-47 0,-41 0,-41 0,-12 0,-12 0,-6 6,0 12,0 12,0 105,0 105,0 111,0 117,-6 117,-12 117,-12 117,-41 117,-41 117,-47 111,-53 105,-53\"/>\n",
       "<text text-anchor=\"middle\" x=\"58.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">gini = 0.24</text>\n",
       "<text text-anchor=\"middle\" x=\"58.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 15</text>\n",
       "<text text-anchor=\"middle\" x=\"58.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [13, 1, 1]</text>\n",
       "</g>\n",
       "<!-- 0&#45;&gt;1 -->\n",
       "<g id=\"edge1\" class=\"edge\">\n",
       "<title>0&#45;&gt;1</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M101.42,-88.95C95.22,-80.07 88.51,-70.46 82.27,-61.54\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"85.07,-59.43 76.47,-53.24 79.33,-63.44 85.07,-59.43\"/>\n",
       "<text text-anchor=\"middle\" x=\"72.1\" y=\"-74.15\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">True</text>\n",
       "</g>\n",
       "<!-- 2 -->\n",
       "<g id=\"node3\" class=\"node\">\n",
       "<title>2</title>\n",
       "<path fill=\"#8139e5\" stroke=\"black\" d=\"M233.5,-53C233.5,-53 147.5,-53 147.5,-53 141.5,-53 135.5,-47 135.5,-41 135.5,-41 135.5,-12 135.5,-12 135.5,-6 141.5,0 147.5,0 147.5,0 233.5,0 233.5,0 239.5,0 245.5,-6 245.5,-12 245.5,-12 245.5,-41 245.5,-41 245.5,-47 239.5,-53 233.5,-53\"/>\n",
       "<text text-anchor=\"middle\" x=\"190.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">gini = 0.0</text>\n",
       "<text text-anchor=\"middle\" x=\"190.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 1</text>\n",
       "<text text-anchor=\"middle\" x=\"190.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [0, 0, 1]</text>\n",
       "</g>\n",
       "<!-- 0&#45;&gt;2 -->\n",
       "<g id=\"edge2\" class=\"edge\">\n",
       "<title>0&#45;&gt;2</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M147.58,-88.95C153.78,-80.07 160.49,-70.46 166.73,-61.54\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"169.67,-63.44 172.53,-53.24 163.93,-59.43 169.67,-63.44\"/>\n",
       "<text text-anchor=\"middle\" x=\"176.9\" y=\"-74.15\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">False</text>\n",
       "</g>\n",
       "</g>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<graphviz.sources.Source at 0x1a419c7c580>"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dot_data = tree.export_graphviz(clf\n",
    "                                ,out_file = None\n",
    "                                ,filled=True\n",
    "                                ,rounded=True\n",
    "                               )\n",
    "graph = graphviz.Source(dot_data)\n",
    "graph"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "b2bac396",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.875"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf.score(Xtrain,Ytrain) #查看模型在训练集上的表现"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "f508c514",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.7142857142857143"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    " clf.score(Xtest,Ytest) #模型在测试集上的预测准确率"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d9460488",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
